package com.ruoyi.mall.controller;

import java.util.List;

import com.ruoyi.mall.domain.MallTimeWarehouse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MallMemberUser;
import com.ruoyi.mall.service.IMallMemberUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员Controller
 *
 * @author ruoyi
 * @date 2021-11-25
 */
@RestController
@RequestMapping("/mall/mallMemberUser")
public class MallMemberUserController extends BaseController
{
    @Autowired
    private IMallMemberUserService mallMemberUserService;

    /**
     * 查询会员列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMemberUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallMemberUser mallMemberUser)
    {
        startPage();
        List<MallMemberUser> list = mallMemberUserService.selectMallMemberUserList(mallMemberUser);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMemberUser:export')")
    @Log(title = "会员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallMemberUser mallMemberUser)
    {
        List<MallMemberUser> list = mallMemberUserService.selectMallMemberUserList(mallMemberUser);
        ExcelUtil<MallMemberUser> util = new ExcelUtil<MallMemberUser>(MallMemberUser.class);
        return util.exportExcel(list, "会员数据");
    }

    /**
     * 获取会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMemberUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallMemberUserService.selectMallMemberUserById(id));
    }

    /**
     * 新增会员
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMemberUser:add')")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallMemberUser mallMemberUser)
    {
        return toAjax(mallMemberUserService.insertMallMemberUser(mallMemberUser));
    }

    /**
     * 修改会员
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMemberUser:edit')")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallMemberUser mallMemberUser)
    {
        return toAjax(mallMemberUserService.updateMallMemberUser(mallMemberUser));
    }

    /**
     * 删除会员
     */
    @PreAuthorize("@ss.hasPermi('mall:mallMemberUser:remove')")
    @Log(title = "会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallMemberUserService.deleteMallMemberUserByIds(ids));
    }

    /**
     * 查询归属人
     */
    @GetMapping("/getUserList")
    public AjaxResult getUserList(MallMemberUser mallMemberUser)
    {
        List<MallMemberUser> list = mallMemberUserService.selectMallMemberUserList(mallMemberUser);
        for (MallMemberUser MMU : list) {
            MMU.setName(MMU.getName()+"--"+MMU.getPhone());
        }
        return AjaxResult.success(list);
    }

    /**
     * 删除银行卡信息
     */
    @GetMapping("/updateDeleteBankCard/{id}")
    public AjaxResult updateDeleteBankCard(@PathVariable("id") Long id)
    {
        MallMemberUser mallMemberUser = new MallMemberUser();
        mallMemberUser.setId(id);
        mallMemberUser.setBankName("");
        mallMemberUser.setBankPhone("");
        mallMemberUser.setBankNumber("");
        mallMemberUser.setBankFullName("");
        mallMemberUserService.updateUserPaymentInfo(mallMemberUser);
        return AjaxResult.success();
    }

    /**
     * 删除微信二维码信息
     */
    @GetMapping("/updateDeleteWxCode/{id}")
    public AjaxResult updateDeleteWxCode(@PathVariable("id") Long id)
    {
        MallMemberUser mallMemberUser = new MallMemberUser();
        mallMemberUser.setId(id);
        mallMemberUser.setWxCode("");
        mallMemberUserService.updateUserPaymentInfo(mallMemberUser);
        return AjaxResult.success();
    }

    /**
     * 删除支付宝维码信息
     */
    @GetMapping("/updateDeleteAliCode/{id}")
    public AjaxResult updateDeleteAliCode(@PathVariable("id") Long id)
    {
        MallMemberUser mallMemberUser = new MallMemberUser();
        mallMemberUser.setId(id);
        mallMemberUser.setAlipayCode("");
        mallMemberUserService.updateUserPaymentInfo(mallMemberUser);
        return AjaxResult.success();
    }

}
